#ifndef DEVICE_H
#define DEVICE_H

#include <stdlib.h>
#include <math.h>

/*A segment is the primitive type that makes up the BS array*/
#define SEGTYPE unsigned long long				//segment 'type'

#define DEVICE_SIZE 268435456					//in bytes

#define SEGMENT_SIZE sizeof(SEGTYPE)			//in bytes, size of a single segment. This is probably 64.

#define SEGMENT_WIDTH (SEGMENT_SIZE * 8)		//how many bits are in a segment

#define SEGMENT_COUNT (DEVICE_SIZE/SEGMENT_SIZE)//How many segments, or elements in the device array, there are

#define FSIB_SIZE 838							//the size in BITS of an FSIB (without use array)
#define FCB_SIZE 819							//the size in BITS of an FCB, plus padding to make it a multiple of address size

SEGTYPE* devicePointer;			//pointer to the 256 MB array
unsigned int blockSize;			//block size in bytes
unsigned int blockCount;		//number of blocks on device
unsigned int blockAddressWidth;	//how many bits in a block >address<

SEGTYPE useArrayStart, useArrayEnd;

/***
 * returns whether the given block is allocated
 */
int get_block_allocation(SEGTYPE blockNumber);

/***
 * Sets the given block as allocated or not allocated
 * (0 means not allocated)
 */
void set_block_allocation(SEGTYPE blockNumer, int isAllocated);


/***
 * Initializes the 256 MB array.
 * MUST be called before doing anything else.
 * @param _blockSize - the block size IN BYTES of a block.
 */
void format_device(int _blockSize);	

/***
 * Reads a single bit from the device
 */
int device_read_bit(SEGTYPE bitNumber);

/***
 * Writes a bit to the device
 */
void device_write_bit(SEGTYPE bitNumber, int value);

/***
 * Prints bitCount bits of the device, starting at startIndex
 */
void print_device(int startIndex, int bitCount);

/*returns log base 2 of x*/
int logb2(int x);

#endif